$(function(){
		$('.Ileft').css('min-height',$(window).height()+'px');
		$('.Iright').css('min-height',$(window).height()-46+'px');
		//header 公用
		function headerhtml(){
			var html='<ul><li class="username">欢迎您！<span>xxx</span>老师</li>';
				html+='<li class="kimout">修改密码</li>';
				html+='<li class="SignOut"><i class="glyphicon glyphicon-off"></i>退出</li></ul>';
				html+='<p class="comTime"><i class="glyphicon glyphicon-time"></i>现在时间:<span class="comTimer"></span></p>';
			$('.Irtop').html(html)
		}
		//footer 公用
		function footerhtml(){
			var html='<p>版权所有：上海社会科学院尚社学人</p>';
            html+='<p>地址：中国上海市黄浦区淮海中路622弄7号 邮编：200020 电话：021-33165064 E-mail:ssxr@sass.com</p>';
            $('.comfooter').html(html);
		}
		//时间 公用
		function gettime(){
		    var data = new Date();
    		var year = data.getFullYear();
    		var mouth = data.getMonth()+1;
    		var day = data.getDate();
    		var hours = data.getHours();
    		var minut = data.getMinutes();
    		var secind = data.getSeconds();
    		if(minut<9){
    			minut='0'+ minut;
    		};
    		if(secind<9){
    			secind='0'+secind;
    		};
    		var date=year+'-'+mouth+'-'+day+' '+hours+':'+minut+':'+secind;
    		$('.comTimer').html(date);
		}
		//获取文件名
		function getHtmlDocName() {
		    var str = window.location.href;
		    str = str.substring(str.lastIndexOf("/") + 1);
		    // str = str.substring(0, str.lastIndexOf("."));
		    return str;
		}
		gettime();
		headerhtml();
		footerhtml();
		setInterval(function(){
			gettime();
		},1000);
		//判断是否登陆
		function loadData(){
				this.data={
					
				}
				this.init();
			}

		// if(app.getItem('userName')){
		// 	function loadData(){
		// 		this.data={
					
		// 		}
		// 		this.init();
		// 	}
		// }else{
		// 	app.go('login.html')
		// }
		loadData.prototype.init=function(){
			$('.username span').html(app.getItem('userName'));
			var _this=this;

			//导航
			$(document).on('click','.margintop .list-group p',function(){
				$('.Ileft .list-group div').hide();
				$(this).next('div').show();
			})

			//退出
			$(document).on('click','.SignOut',function(){
				var data = {
			        'userToken':app.getItem('userToken'),
          			'userId':app.getItem('userId')
			    };
			    app.post(app.url.api_base + "login/logout.do", data,
			        function(req) {
			            if(req.code==0){
			            	app.removeItem('userName','');
                    		app.removeItem('userId','');
                    		app.removeItem('userToken','');
		                    app.go('login.html');
		                } else {
		                	Prompt.show(req.message);
		                }
			        });
			});

			//弹出修改密码框
			$(document).on('click','.kimout',function(){
				var html='';
					html+='<div class="modal fade" id="ChangePass" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">';
					html+='<div class="modal-dialog" role="document">';
					html+='<div class="modal-content"><div class="modal-header">';
					html+='<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
					html+='<h4>修改密码</h4></div>';
					html+='<div class="modal-body"><div class="row">';
					html+='<div class="col-md-8 col-md-offset-2"><div class="form-group">';
					html+='<label for="inputEmail3" class="col-sm-4 control-label">新密码：</label>';
					html+='<div class="col-sm-8">';
					html+='<input type="password" class="form-control" id="newpass" maxlength="12" placeholder="请输入新密码" />';
					html+='</div></div><div class="form-group">';
					html+='<label for="inputEmail3" class="col-sm-4 control-label">确认密码：</label><div class="col-sm-8">';
					html+='<input type="password" class="form-control" id="querenpass" maxlength="12" placeholder="请再次输入新密码" />';
					html+='</div></div></div></div></div><div class="modal-footer">';
					html+='<button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>';
					html+='<button type="button" class="btn btn-primary">保存密码</button>';
					html+='</div></div></div></div>';
					$('body').append(html);
					$('#ChangePass').modal('show');
			})	

			//修改密码
			$(document).on('click', '#ChangePass .btn-primary', function() {
			    var newpass = $('#newpass').val();
			    var again = $('#querenpass').val();
			    if (newpass == '') {
			        Prompt.show('新密码不能为空!', '操作提示', function() {});
			        return false;
			    }
			    if (again == '') {
			        Prompt.show('确认密码不能为空!', '操作提示', function() {});
			        return false;
			    }
			    if (newpass != again) {
			        Prompt.show('两次密码不一致!', '操作提示', function() {});
			        return false;
			    }
			    var data = {
			        'password': $.md5(newpass),
			        'confimPassword': $.md5(again),
			        'userToken':app.getItem('userToken'),
          			'userId':app.getItem('userId')
			    };
			    app.post(app.url.api_base + "login/changePasswordByUser.do", data,
			        function(req) {
			            if (req.code == 0) {
			                $('#ChangePass').modal('hide');
			            }
			            Prompt.show(req.message);
			        });
			})
		}

		new loadData();
})


